import java.util.*;

public class Test {
    public static void main(String[] args) {
        LinkedList<Integer> linkedList2 = new LinkedList<>();
        linkedList2.add(1);//所有的add默认都是尾插
        linkedList2.addLast(3);
        linkedList2.addLast(4);
        linkedList2.addLast(5);

        System.out.println("=====ListIterator=====");
        //从指定坐标开始打印
        ListIterator<Integer> lis2 = linkedList2.listIterator(linkedList2.size());
        //  hasPrevious 有没有上一个
        //逆序打印
        while (lis2.hasPrevious()){
            System.out.print(lis2.previous()+" ");
        }
        /*ListIterator<Integer> lit2 = linkedList2.listIterator(2);
        while (lit2.hasNext()){
            System.out.print(lit2.next()+" ");
        }*/
        System.out.println();

        System.out.println("=====ListIterator=====");
        ListIterator<Integer> lit = linkedList2.listIterator();
        while (lit.hasNext()){
            System.out.print(lit.next()+" ");
        }
        System.out.println();

        System.out.println("======for each======");
        for (Integer x: linkedList2) {
            System.out.print(x+" ");
        }
        System.out.println();

        System.out.println("=========for========");
        for (int i = 0; i < linkedList2.size(); i++) {
            System.out.print(linkedList2.get(i)+" ");
        }
        System.out.println();

        System.out.println("=======迭代器========");
        Iterator<Integer> it = linkedList2.iterator();
        while (it.hasNext()){
            System.out.print(it.next()+" ");
        }
        System.out.println();
    }
    public static void main2(String[] args) {
        LinkedList<Integer> linkedList1 = new LinkedList<>();
        LinkedList<Integer> linkedList2 = new LinkedList<>();
        List<Integer> integerList = new LinkedList<>();

        linkedList2.add(1);//所有的add默认都是尾插
        linkedList2.addFirst(2);
        linkedList2.addLast(3);
        linkedList2.addLast(4);
        linkedList2.addLast(5);
        System.out.println(linkedList2);
        ArrayList<Integer>  list = new ArrayList<>();
        list.add(11);
        list.add(21);
        list.add(31);

        linkedList2.addAll(list);
        System.out.println(linkedList2);

        linkedList2.remove(2);
        System.out.println(linkedList2);


    }




    public static void main1(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.addLast(11);
        myLinkedList.addLast(21);
        myLinkedList.addLast(31);
        myLinkedList.addLast(41);
        myLinkedList.addLast(51);

        myLinkedList.display();
        /*System.out.println("=============");
        myLinkedList.addIndex(0,9);
        myLinkedList.display();*/
        System.out.println("=============");
        /*myLinkedList.removeAllKey(1);
        myLinkedList.display();*/
        myLinkedList.clear();
        myLinkedList.display();
    }
}
